package com.ctshk.sapp.order.tour.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.order.tour.dto.ApprovalRefundListDTO;
import com.ctshk.rpc.order.tour.dto.SeriesOrderTouristRefundListDTO;
import com.ctshk.rpc.order.tour.req.*;
import com.ctshk.rpc.order.tour.service.ISeriesOrderTouristRefundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 系列团游客退款记录 前端控制器
 * </p>
 *
 * @author 谭响
 * @since 2021-01-28
 */
@Api(value="退款", tags="退款")
@RestController
@RequestMapping("/series/order/tourist/refund")
public class SeriesOrderTouristRefundController extends BaseController {

    @DubboReference
    private ISeriesOrderTouristRefundService iSeriesOrderTouristRefundService;

    @ApiOperation(value = "列表", notes = "列表（退款管理）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "退款管理", operDesc = "退款管理")
    @PostMapping("/list")
    public Result<PageResponse<SeriesOrderTouristRefundListDTO>> list(@RequestBody @Valid SeriesOrderTouristRefundListReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return Result.success(iSeriesOrderTouristRefundService.list(req));
    }

    @ApiOperation(value = "申请退款", notes = "添加（退款管理-退款-發起審批）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "退款管理-退款-發起審批", operDesc = "退款管理-退款-發起審批")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid SeriesOrderTouristRefundAddReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return iSeriesOrderTouristRefundService.add(req);
    }

    @ApiOperation(value = "退款计算", notes = "添加计算（退款管理-退款）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "退團管理-申請退團", operDesc = "退團管理-申請退團")
    @PostMapping("/add/calculation")
    public Result addCalculation(@RequestBody @Valid SeriesOrderTouristRefundAddCalculationReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return iSeriesOrderTouristRefundService.addCalculation(req);
    }

    @ApiOperation(value = "操作退款", notes = "确认（退款管理-操作退款）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "退款管理-操作退款", operDesc = "退款管理-操作退款")
    @PostMapping("/confirm")
    public Result confirm(@RequestBody @Valid SeriesOrderTouristRefundConfirmReq req) {
        return iSeriesOrderTouristRefundService.confirm(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "审核", notes = "审核")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "审核", operDesc = "审核")
    @PostMapping("/approval")
    public Result approval(@RequestBody SeriesOrderTouristRefundApprovalReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return iSeriesOrderTouristRefundService.approval(req);
    }

    @ApiOperation(value = "审批中心-退款信息列表", notes = "审批中心-退款信息列表(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "审批中心-退款信息列表", operDesc = "审批中心-退款信息列表")
    @PostMapping("/approval-refund-list")
    public Result<List<ApprovalRefundListDTO>> approvalRefundList(@RequestBody @Valid ApprovalIdReq req) {
        return iSeriesOrderTouristRefundService.approvalRefundList(req);
    }

}
